import PasswordPopu from '../../components/PasswordPopu/PasswordPopu.vue';
import PromptPopup from '../../components/PromptPopup/PromptPopup.vue';
import util from '@/http/util.js';
import api from '../../http/api';
export default {
	components: {
		PasswordPopu,
		PromptPopup
	},
	data() {
		return {
			poputitle: "", //修改弹窗标题
			popuold: "", //修改弹窗标题
			popunew: "", //修改弹窗标题

			chPopup: '',

			userInfo: {}, //用户信息
			statusBarHeight: 0, //导航栏高度
		};
	},
	onLoad() {
		// 动态获取状态栏高度（App 端）
		// #ifdef APP-PLUS
		this.statusBarHeight = plus.navigator.getStatusbarHeight();
		// #endif
	},
	onShow(){
		this.userInfo = util.getUserInfo();
	},
	methods: {
		OrderRecord() {
			uni.navigateTo({
				url: '/pages/My/HistoricalOrder/index'
			})
		},
		DetailedContent() {
			uni.navigateTo({
				url: '/pages/My/DetailedContent/index'
			})
		},
		CommissionRebate() {
			uni.navigateTo({
				url: '/pages/My/CommissionRebate/index'
			})
		},
		// 显示交易密码弹窗
		tradePassword() {
			this.poputitle = "修改交易密码";
			this.popuold = "旧交易密码";
			this.popunew = "新交易密码";
			this.chPopup = 'modify';
			this.$refs.tradePassword.open();
		},
		//显示登录密码弹窗
		loginPassword() {
			this.poputitle = "修改登录密码";
			this.popuold = "旧登录密码";
			this.popunew = "新登录密码";
			this.chPopup = 'login';
			this.$refs.tradePassword.open();
		},
		// 处理发送短信验证码
		handleSendSms() {
			// 这里实现发送短信验证码的逻辑
			console.log("发送短信验证码到用户手机");

			// 实际项目中，这里应该调用API发送短信
			uni.showToast({
				title: "验证码已发送",
				icon: "success"
			});
		},

		// 处理确认修改交易密码
		handleConfirmChange(data) {
			console.log("修改交易密码:", data);
			if (this.chPopup == 'modify') {
				//修改交易密码
				api.modifyPassword({
					'old_password': data.oldPassword,
					'now_password': data.newPassword,
					'renow_password': data.confirmPassword,
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: "密码修改成功",
							icon: "success"
						});
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				}).catch(err => {

				})
			} else {
				//修改登录密码
				api.loginPassword({
					'old_password': data.oldPassword,
					'now_password': data.newPassword,
					'renow_password': data.confirmPassword,
				}).then(res => {
					if (res.code == 1) {
						uni.showToast({
							title: "密码修改成功",
							icon: "success"
						});
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
					}
				}).catch(err => {

				})
			}
			// 关闭弹窗
			this.$refs.tradePassword.closeModal();
		},
		// 处理弹窗关闭
		handleModalClose() {
			console.log("弹窗已关闭");
		},
		//确认弹窗退出登录
		collectMoney() {
			console.log("sssssssssss")
			this.$refs.pointOut.closeModal();
			uni.navigateTo({
				url: '/pages/Login/index'
			})
		},
		SetUp() {
			uni.navigateTo({
				url: '/pages/My/SetUp/index'
			})
		},
		//退出登录
		LogOut() {
			this.$refs.pointOut.open();
		},
		JumpLink() {
			api.deploy().then(res=>{
				if(res.code==1){
					  //#ifdef APP-PLUS
					  plus.runtime.openURL(res.data.gfqunzu, (err) => {
					    if (err) {
					      uni.showToast({ title: '打开浏览器失败', icon: 'none' });
					      // 降级方案：复制链接到剪贴板
					      uni.setClipboardData({
					        data: res.data.gfqunzu,
					        success: () => {
					          uni.showToast({ title: '链接已复制，请手动打开浏览器粘贴', icon: 'none' });
					        }
					      });
					    }
					  });
					  // #endif
					  
					  // #ifdef H5
					  window.open(res.data.gfqunzu, '_blank');
					  // #endif
				}else{
					uni.showToast({ title: res.msg, icon: 'none' });
				}
			})
		}
	},
	mounted() {
		// 获取用户信息
		this.userInfo = util.getUserInfo();
	}
};